import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

import Agency from '@/views/index/userindex';
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/login',
    // 修改重定向
    // redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'dashboard',
      component: () => import('@/views/wxmini/dashboard/index'),
      meta: { title: '数据总览', icon: 'dashboard' }
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/indexnew'),
    hidden: true
  },
  {
    path: '/newUserSelect',
    name: "newUserSelect",
    component: () => import('@/views/login/newUserSelect'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/login/register'),
    hidden: true
  },

  {
    path: '/prolist',
    component: () => import('@/views/index/userindexlist/prolist'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/diyview',
    component: () => import('@/views/diyview/index')
  },
  {
    path: '/preview',
    component: () => import('@/views/diyview/preview/preview')
  },
  {
    path: '/allfun',
    component: Layout,
    children: [{
      path: 'index',
      name: 'allfun',
      component: () => import('@/views/wxmini/allfun/index'),
      meta: { title: '总览', icon: 'dashboard' }
    }]
  },
  // 微信授权页面
  {
    path: '/empower',
    component: () => import('@/views/empower/index'),
    hidden: true
  },
  // 代理端微信授权页面
  {
    path: '/agent',
    component: () => import('@/views/empower/agent'),
    hidden: true
  },
  // 授权成功后跳转页面
  {
    path: '/callback',
    component: () => import('@/views/empower/callback'),
    hidden: true
  },
  {
    path: '/config',
    name: 'Config',
    component: Layout,
    children: [{
      path: 'configpro',
      name: 'ConfigPro',
      component: () => import('@/views/wxmini/config/index'),
      meta: { title: '配置信息', icon: 'example' }
    }]
  },
  {
    path: '/userInfo',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'User',
        component: () => import('@/views/wxmini/user/index'),
        meta: { title: '用户管理', icon: 'user' }
      }
    ]
  },
  {
    path: '/product',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'product',
        component: () => import('@/views/wxmini/product/index'),
        meta: { title: '产品对接', icon: 'linkper' }
      }
    ]
  },
  {
    path: '/pagepro',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'pagepro',
        component: () => import('@/views/wxmini/configpage/index'),
        meta: { title: '项目管理', icon: 'linkper' }
      }
    ]
  },
  {
    path: '/shopmgt',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'shopmgt',
        component: () => import('@/views/wxmini/shopmanagement/index'),
        meta: { title: '店铺管理', icon: 'shop' }
      }
    ]
  },
  {
    path: '/plugmgt',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'plugmgt',
        component: () => import('@/views/wxmini/pluginmanagement/index'),
        meta: { title: '插件管理', icon: 'plug' }
      }
    ]
  },
  {
    path: '/funmgt',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'funmgt',
        component: () => import('@/views/wxmini/funmangement/index'),
        meta: { title: '功能管理', icon: 'fun' }
      }
    ]
  },
  {
    path: '/diymodule',
    component: () => import('@/views/diymodule/index')
  },
  {
    path: '/manage',
    component: Agency,
    redirect: '/manage/center',
    hidden: true,
    children: [
      {
        path: 'center',
        component: () => import('@/views/index/userindexcon/center')
      },
      {
        path: 'config',
        component: () => import('@/views/index/userindexcon/config')
      },
      {
        path: 'order',
        component: () => import('@/views/index/userindexcon/order')
      },
      {
        path: 'pandect',
        component: () => import('@/views/index/userpandect/pandect')
      },
      {
        path: 'tuiguang',
        component: () => import('@/views/index/userpromote/userpromote')
      },
      {
        path: 'taocan',
        component: () => import('@/views/index/usersetmeal/usersetmeal')
      },
      {
        path: 'shouyi',
        component: () => import('@/views/index/Incomestatistics/Incomestatistics')
      }
    ]
  },
  {
    path: '/addpro',
    component: () => import('@/views/index/usertemplate/addtemplate')
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
